#ifndef PAGEHVAC_H
#define PAGEHVAC_H

#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QSignalMapper>
#include <QTimer>
#include "globalconfig.h"

#define ROWS_ONE_PAGE 15

namespace Ui {
class PageHvac;
}

class PageHvac : public QWidget
{
    Q_OBJECT

public:
    explicit PageHvac(QWidget *parent = nullptr);
    ~PageHvac();
    enum
    {
        HVACStat_SalTemp,
        HVACStat_TargetTemp,
        HVACStat_UnitStat,
        HVACStat_ControlMode,
        HVACStat_LowerLoad,
        HVACStat_NADamper,
        HVACStat_RADamper,
        HVACStat_Compressor,
        HVACStat_Condenserfan,
        HVACStat_Ventor,
        HVACStat_PM25,
        HVACStat_CO2,
        HVACStat_TVOC,
        HVACStat_PressureDifference,
        HVACStat_Humidity,
        HVACStat_EnergyMonth1,
        HVACStat_EnergyMonth2,
        HVACStat_Count
    };
    enum
    {
      WholeTrain,Mc1,Mp1,Mp2,Mc2
    };
    void setPageActive(bool xActive);
    void setHVACStat(int item, int index, uint16_t value);
    void syncHVACMode(int mode);
    void syncHVACTemp(int sal,int temp);
private slots:
    void on_BtnNext_clicked();
    void on_BtnPre_clicked();
    void slot_SalSelect(int sal);
    void slot_SalMode(int mode);
    void on_Btn_Sub_clicked();
    void on_Btn_Add_clicked();
    void on_Btn_CloseDAMP_clicked();
    void on_Btn_OpenDAMP_clicked();
signals:
    void CloseNADamper(bool xClose);
    void signal_SendHvacMode(int mode,bool xValid);
    void signal_HvacTemp(int index,int temp);
    void signal_OpenNADamper(bool xOpen);
    void signal_CloseNADamper(bool xClose);
private:
    Ui::PageHvac *ui;
    QList<QList <QLabel *>> m_lHVACStatList;
    QStringList m_lHVACStatNameList;
    QList<uint8_t> m_lHVACStatCntOfOneCar;
    QList<QWidget *> m_lDisplayWidgets;
private:
    QList<QPushButton *> m_lSalSelBtnList;
    QList<QPushButton *> m_lModeBtnList;
    int m_nWhichSalSelected;
    QSignalMapper *m_pSalSelMapper=nullptr;
    QSignalMapper *m_pSalModeMapper=nullptr;
    int m_nHVACMode;
    void AddTemp();
    void SubTemp();
    QList<QLabel*> m_lHVACTempList;
private:
    void InitHVACStatLabels();
    void InitBtnsMapper();
    void SetPosition(QWidget* w, int car, uint8_t row, uint8_t col, uint8_t total, bool xReverse=false);
private:
    float m_nStatLabelWidth_Car;
    float m_nStatLabelHeight;
    float m_nStatLabelStartY;
    float m_nStatLabelSpaceX;
    float m_nStatLabelSpaceY;
private:
    void setDefaultStat();
};

#endif // PAGEHVAC_H
